<template>
    <el-dialog class="add-budget" :title="`上传会签确认函`" :visible.sync="visible" :before-close="close" width="600px">
        <el-form label-width="140px">
            <el-form-item label="会签确认函">
                <elUploadImage :limit="1" :multiple="false" v-model="fileList"></elUploadImage>
            </el-form-item>
        </el-form>
        <div slot="footer">
            <el-button type="primary" @click="submit">确认</el-button>
            <el-button @click="close">关闭</el-button>
        </div>
    </el-dialog>
</template>
<script>
import elUploadImage from '@/components/el-upload-image.vue';
export default {
    data() {
        return {
            visible: false,
            fileList: []
        }
    },
    props: {
        value: {
            type: Object,
            default: null
        }
    },
    watch: {
        value(val) {
            this.visible = val ? true : false
        }
    },
    components: { elUploadImage },
    methods: {
        close() {
            Object.assign(this.$data, this.$options.data())
            this.$emit('update:value', null)
        },
        async submit() {
            try {
                if (!this.fileList.length) {
                    this.$message.error('请上传会签确认函')
                    return
                }
                await this.$post({
                    url: '/admin/project.ProjectBudget/budgetCheck',
                    data: {
                        status: this.value.status,
                        id: this.value.id,
                        checksign: this.fileList[0].url
                    },
                    successTip: true
                })
                this.$emit('update')
            } catch(err){
                this.$message.error(err)
            }
        }
    }
}
</script>